package com.isesol.ime.dal.mapper;

import com.isesol.arch.common.dal.*;
import com.isesol.ime.dal.model.*;
import com.isesol.ime.dal.model.dto.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.*;

import java.util.*;

/**
 * 订阅
 *
 * @author peter zhang
 */
@Repository
public interface SubscriptionMapper extends GenericMapper<SubscriptionDO> {

	List<SubscriptionDO> findByMachineIdAndRuleName(@Param("machineId") String machineId,
	                                                @Param("ruleName") String ruleName);

	List<Long> findValidSubIdByMachineIdAndRuleName(@Param("machineId") String machineId,
	                                                @Param("ruleName") String ruleName);

	List<SubscriptionDetailDTO> findDetail(@Param("machineId") String machineId,
	                                       @Param("ruleName") String ruleName);

	List<SubscriptionDO> findByMsgIdAndStatus(@Param("msgId") long msgId,
	                                          @Param("status") String status);

	List<SubscriptionDO> findByMachineIdAndStatus(@Param("ruleName") String ruleName,
	                                              @Param("machineId") String machineId,
	                                              @Param("status") String status);

	@Select("select * from ime.subscription where machine_id=#{machineId} and msg_id=#{msgId}")
	SubscriptionDO findByMachineIdAndMsgId(@Param("machineId") String machineId,
	                                       @Param("msgId") long msgId);

	List<SubscriptionDTO> find(@Param("machineId") String machineId,
	                           @Param("msgId") String msgId,
	                           @Param("machineType") String machineType,
	                           @Param("ruleName") String ruleName);

	List<PushDTO> findMachineIdByMachineType(@Param("machineType") String machineType);

	List<PushDTO> findOneByMachineId(@Param("machineId") String machineId);

}
